package org.goochasca

import java.awt.Color

private[goochasca] trait Title extends Chart {
  
  private var title: Option[String] = None
  private var color: Option[Color] = None
  private var size: Option[Int] = None
  
  def setTitle(title: String, color: Color, size: Int) {
    this.title = Some(title.trim)
    this.color = Some(color)
    this.size = Some(size)
  }

  def setTitle(title: String, color: Color) {
    this.title = Some(title.trim)
    this.color = Some(color)
    this.size = None
  }
  
  def setTitle(title: String) {
    this.title = Some(title.trim)
    this.color = None
    this.size = None
  }
  
  import Chart._
  protected abstract override def appendParms(sb: StringBuilder) {
    super.appendParms(sb)
    if (title.isDefined && title.get.length > 0) {
      val lines = title.get.split("\r\n")
      sb append "&chtt=" append escape(lines.first)
      for (line <- lines.drop(1))
        sb append '|' append escape(line)
      if (color.isDefined) {
        sb append "&chts=" 
        Colorific.appendColors(color, sb)
        if (size.isDefined) sb append ',' append size.get 
      }
    }
  }
}
